﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐
    //
    // 文件名：PurchaseOrderDetail_NoConfirm.cs
    // 文件功能描述：采购单明细：未确认明细
    // 创建标识：吕海乐 2009-05-16
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Hospitals.Procurement
{
    public partial class PurchaseOrderDetail_NoConfirm : BasePage
    {
        public PurchaseOrderDetail_NoConfirm()
        {
            this.ModuleNo = Module.采购单管理.ToString();
        }

        IBLL_Purchase ip = Factory.BLL_Purchase();
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HZ.DrugTrade.Web.Function.IsThreeLevel())//项目查询条件仅三级医院可见
            {
                this.ddlProjectid.Visible = false;
                this.lblProjectid.Visible = false;
            }
            if (!IsPostBack)
            {
                //绑定所有项目
                //ProcurementProject procurementProject = new ProcurementProject();
                //procurementProject.ProcureStartTimeFrom = Convert.ToDateTime("1890-01-01");
                //procurementProject.ProcureStartTimeTo = Convert.ToDateTime("2099-12-31");
                //procurementProject.ProcureEndTimeFrom = Convert.ToDateTime("2000-01-01");
                //procurementProject.ProcureEndTimeTo = Convert.ToDateTime("2099-12-31");
                //int temp;
                //IList<ProcurementProject> projectList = ipb.GetProjectByWhere(procurementProject, 1, 0, out temp);
                //ddlProject.DataSource = projectList;
                //ddlProject.DataTextField = "ProjectName";
                //ddlProject.DataValueField = "ProjectID";
                //ddlProject.DataBind();
                //ListItem item = new ListItem();
                //item.Text = Constants.ALL_ITEM_TEXT;
                //item.Value = Constants.ALL_ITEM_VALUE;
                //ddlProject.Items.Insert(0, item);
                SetBind();
            }
        }

        /// <summary>
        /// 绑定符合条件的采购明细
        /// </summary>
        private void SetBind()
        {
            Model.Query.PurchaseOrderDetail qPurchaseOrderDetail = new HZ.DrugTrade.Model.Query.PurchaseOrderDetail();
            qPurchaseOrderDetail.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            qPurchaseOrderDetail.Outlookc = txtOutLook.Text.Trim();
            qPurchaseOrderDetail.OrderName = txtOrderName.Text.Trim();
            //qPurchaseOrderDetail.ProjectID = ddlProject.SelectedItem.Value;
            qPurchaseOrderDetail.Unit = txtUnit.Text.Trim();
            qPurchaseOrderDetail.GoodsName = txtGoodsName.Text.Trim();
            qPurchaseOrderDetail.PinyinCode = this.txtpinyincode.Text.Trim();
            //if (!string.IsNullOrEmpty(txtFactor.Text.Trim()))
            //{
            //    qPurchaseOrderDetail.Factor =Convert.ToInt32(txtFactor.Text.Trim());
            //}
            //qPurchaseOrderDetail.PinyinCode = this.txtPinyinCode.Text.Trim();
            //qPurchaseOrderDetail.ProjectID = this.ddlProjectid.SelectedValue;
            if (this.ddlProjectid.Visible != false)
            {
                qPurchaseOrderDetail.ProjectID = this.ddlProjectid.SelectedValue;
            }
            else
            {
                qPurchaseOrderDetail.ProjectID = "0001";
            }
            qPurchaseOrderDetail.CompanyName_PS = txtProduceCompany_PS.Text.Trim();
            qPurchaseOrderDetail.OrderDetailState = 1;
            qPurchaseOrderDetail.SortFields = "ExecuteTime DESC,OrderName Desc";

            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount;
            IList<Model.View.PurchaseOrderDetail> purchaseOrderDetailList = ip.GetPurchaseOrderDetailByWhere(qPurchaseOrderDetail, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwNoConfirm.PageSize = AspNetPager1.PageSize;
            gvwNoConfirm.DataSource = purchaseOrderDetailList;
            gvwNoConfirm.DataBind();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            SetBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        /// <summary>
        /// 简单查询与高级查询间的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                //清空数据
                //txtFactor.Text = "";
                txtOrderName.Text = "";
                txtProduceCompany_PS.Text = "";
                //txtPinyinCode.Text = "";
                txtUnit.Text = "";
                txtGoodsName.Text = "";
                //ddlProject.SelectedIndex = -1;
            }
        }
        /// <summary>
        /// 导出2009-11-25
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {

            Model.Query.PurchaseOrderDetail qPurchaseOrderDetail = new HZ.DrugTrade.Model.Query.PurchaseOrderDetail();
            qPurchaseOrderDetail.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            qPurchaseOrderDetail.Outlookc = txtOutLook.Text.Trim();
            qPurchaseOrderDetail.OrderName = txtOrderName.Text.Trim();
            //qPurchaseOrderDetail.ProjectID = ddlProject.SelectedItem.Value;
            qPurchaseOrderDetail.Unit = txtUnit.Text.Trim();
            qPurchaseOrderDetail.GoodsName = txtGoodsName.Text.Trim();
            qPurchaseOrderDetail.PinyinCode = this.txtpinyincode.Text.Trim();
            //if (!string.IsNullOrEmpty(txtFactor.Text.Trim()))
            //{
            //    qPurchaseOrderDetail.Factor = Convert.ToInt32(txtFactor.Text.Trim());
            //}
            //qPurchaseOrderDetail.PinyinCode = this.txtPinyinCode.Text.Trim();
            //qPurchaseOrderDetail.ProjectID = this.ddlProjectid.SelectedValue;
            if (this.ddlProjectid.Visible != false)
            {
                qPurchaseOrderDetail.ProjectID = this.ddlProjectid.SelectedValue;
            }
            else
            {
                qPurchaseOrderDetail.ProjectID = "0001";
            }
            qPurchaseOrderDetail.CompanyName_PS = txtProduceCompany_PS.Text.Trim();
            qPurchaseOrderDetail.OrderDetailState = 1;
            qPurchaseOrderDetail.SortFields = "ExecuteTime DESC,OrderName Desc";
            int total = 0;
            IList<Model.View.PurchaseOrderDetail> purchaseOrderDetailList = ip.GetPurchaseOrderDetailByWhere(qPurchaseOrderDetail, 1, 0, out total);
            System.Data.DataTable dt = HZ.Data.ModelConvert.GetDataTableFromModel(purchaseOrderDetailList);
            //HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gvwNoConfirm, this);
            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gvwNoConfirm);
        }

        /// <summary>
        /// 撤单  2009-11-19
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btnAbandon_Click(object sender, EventArgs e)
        //{
        //    List<PurchaseOrderDetail> detailList = new List<PurchaseOrderDetail>();
        //    string ids = Request["checkbox1"];
        //    if(!string.IsNullOrEmpty(ids))
        //    {
        //        //获取选择的明细
        //        string[] arrayId = ids.Split(',');
        //        for (int i = 0; i < arrayId.Length; i++)
        //        {
        //            PurchaseOrderDetail aDetail = new PurchaseOrderDetail();
        //            aDetail.OrderDetailID = arrayId[i];
        //            detailList.Add(aDetail);
        //        }
        //        //执行撤单操作
        //        if (ip.UnconfirmPurchaseOrderDetail_Batch(detailList) == 1)
        //        {
        //            SetBind();
        //        }
        //        else
        //        {
        //            PageError("撤单失败！",this.ReturnUrl);
        //        }
        //    }
        //}
    }
}
